package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dao.AdminDAO;
import entity.Admin;

/**
 * Servlet implementation class JudgeAdminServlet
 */
@WebServlet("/JudgeAdminServlet")
public class JudgeAdminServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public JudgeAdminServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		//response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		
		String type = request.getParameter("type");
		int admin_id = Integer.parseInt(request.getParameter("id"));
		if(type.equals("0")) {//type=0，为删除admin操作
			dao.AdminDAO.getInstance().delete(admin_id);
			RequestDispatcher view = request.getRequestDispatcher("ManageAdminServlet");
			view.forward(request, response);
		}else {
			//等dao写好，这底下一波数据需要修改一下
			Admin a = AdminDAO.getInstance().get(admin_id);//查询目标修改的admin
			request.setAttribute("modify_admin_id", admin_id);
			request.setAttribute("modify_admin_name", a.getAdmin_name());
			request.setAttribute("modify_admin_password", a.getAdmin_password());
			request.setAttribute("modify_admin_tel", a.getAdmin_tel());
			RequestDispatcher view = request.getRequestDispatcher("admin_Modify.jsp");
			view.forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}

}
